/*    
 * Copyright (c) 2013 ISoftStone, Inc.
 * All right reserved.
 *
 * 文件名：      UserServiceImpl.java
 * 作者:     Jacky Wang
 * 创建日期： 2013-7-24 下午02:20:40
 * 版本：           
 *
 */
package com.isoftstone.industry.aaa.core.service.assist.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.isoftstone.industry.persistance.bean.AccountItem;
import com.isoftstone.industry.persistance.bean.BillingCycle;
import com.isoftstone.industry.persistance.bean.ChargingItem;
import com.isoftstone.industry.persistance.bean.User;
import com.isoftstone.industry.aaa.core.dao.assist.UserDao;
import com.isoftstone.industry.aaa.core.service.assist.IUserService;
import com.isoftstone.modules.core.persistence.IGenericDao;
import com.isoftstone.modules.core.service.impl.GenericServiceImpl;
import com.isoftstone.modules.core.utils.DateUtils;

/**
 *
 * @author jacky
 */
@Service
public class UserServiceImpl extends GenericServiceImpl<User, String> implements IUserService
{
	@Resource
	private UserDao userDao;
	
	@Override
	public IGenericDao<User, String> getDao()
	{
		return userDao;
	}

	@Override
	public List<User> findNeedChargingUsers()
	{
		Date today = DateUtils.today();
		Date start = DateUtils.getFirstDayOfMonth(today);
		Date end = DateUtils.getLastDayOfMonth(today);
		return userDao.findByChargingItemStatusAndDate(ChargingItem.Status.VALID, start, end);
	}

	@Override
	public List<User> findNeedAccountingUsers()
	{
		return userDao.findNeedAccountingUsers();
	}

	@Override
	public List<User> findOweFeeUsers()
	{
		//账单有欠费的用户
		List<User> userList1 = userDao.findByBillPayableAmountGreaterThan0();
		//预付费服务没有预支付的用户
		List<User> userList2 = userDao.findByAcctItemStatusAndPrepaid(AccountItem.Status.NON_CHARGE_OFF, true);
		List<User> userList = new ArrayList<User>();
		userList.addAll(userList1);
		for (User user : userList2)
		{
			if (!userList1.contains(user))
			{
				userList.add(user);
			}
		}
		return userList;
	}

	@Override
	public boolean hasChargingProductInst(String userId,
			BillingCycle billingCycle) {
		return userDao.hasChargingProductInst(userId, billingCycle.getEndDate());
	}

}
